//获取应用实例
const app = getApp();
Page({
  data: {
    codeId: '', //验证码
    name: '', //姓名
    accountId: '', //微信号
    codename: '获取验证码',
    wx: '',
    amount: 0,
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
  },
  onLoad: function() {
    this.getStatistics();

    var that = this;

    /**
     * 获取当前设备的宽高
     */
    wx.getSystemInfo({

      success: function(res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
  },

  //  tab切换逻辑
  swichNav: function(e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },

  bindChange: function(e) {

    var that = this;
    that.setData({
      currentTab: e.detail.current
    });

  },

  //获取用户余额变动记录
  getRecord: function () {
    var that = this;
    wx.request({
      url: app.globalData.api + '/app.php?c=UserBalanceRecord&a=getBalanceRecord',
      data: {
        token: app.globalData.token,//手机号码
        page: 1,
        per: 100
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success(res) {
        console.log(res)
        if (res.data.code == 0) {
          that.setData({
            recordList: res.data.data.list
          })
        } else {
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }

      }
    })
  },
  //获取收益统计
  getStatistics: function() {
    var that = this;
    wx.request({
      url: app.globalData.api + '/app.php?c=UserBalanceRecord&a=statistics',
      data: {
        token: app.globalData.token,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success(res) {
        console.log(res)
        if (res.data.code == 0) {
         that.setData({
           amount: res.data.data.amount,
          today: res.data.data.today,
          yesterday: res.data.data.yesterday,
          sevenday: res.data.data.sevenday,
          lastmonth: res.data.data.lastmonth,
         })
        }else{
          wx.showToast({
            title: '' + res.data.msg, //提示文字
            duration: 2000, //显示时长
            mask: true, //是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { }, //接口调用成功
            fail: function () { }, //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }
        that.getRecord();
      }
    })
  },


});